package com.fast.develop.api.rest.registor;

import com.fast.develop.api.rest.RuntimeRest;
import com.fast.develop.core.enums.RequestMethod;
import com.fast.develop.core.persistence.BatchObject;
import com.fast.develop.core.properties.DomainRuntimeProperties;
import com.fast.develop.core.web.AbstractMappingRegistor;
import com.fast.develop.core.web.MappingInfo;
import com.fast.develop.core.web.MappingRegistor;
import com.fast.develop.integration.web.MvcMappingHandlerMapping;
import lombok.SneakyThrows;

/**
 * @author 莫寅
 * @createTime 2022-06-18 04:52
 * @desc：
 */
public class RuntimeMappingRegistor extends AbstractMappingRegistor implements MappingRegistor {


    public static final String KEY = "/meta";


    public RuntimeMappingRegistor(MvcMappingHandlerMapping mvcMappingHandlerMapping, DomainRuntimeProperties domainRuntimeProperties, RuntimeRest runtimeRest) {
        super(mvcMappingHandlerMapping, domainRuntimeProperties, runtimeRest);
    }


    @Override
    @SneakyThrows
    public void registerMapping() {
        MappingInfo reload = new MappingInfo(new String[]{getPath("configuration/reload")}, new RequestMethod[]{RequestMethod.POST});
        registerMapping(reload, RuntimeRest.class.getDeclaredMethod("reload"));

        MappingInfo batch = new MappingInfo(new String[]{getPath("{model}/batch")}, new RequestMethod[]{RequestMethod.POST});
        registerMapping(batch, RuntimeRest.class.getDeclaredMethod("batch", String.class, BatchObject.class));
    }

    @Override
    public String type() {
        return KEY;
    }



    @Override
    protected String getKey() {
        return KEY;
    }
}
